<style type="text/css">
	body { font-size: 62.5%; }
	label, input { display:block; }
	input.text { margin-bottom:12px; width:95%; padding: .4em; }
	fieldset { padding:0; border:0; margin-top:25px; }
	h1 { font-size: 1.2em; margin: .6em 0; }
	.ui-button { outline: 0; margin:0; padding: .4em 1em .5em; text-decoration:none;  !important; cursor:pointer; position: relative; text-align: center; }
	.ui-dialog .ui-state-highlight, .ui-dialog .ui-state-error { padding: .3em;  }
</style>
<script type="text/javascript">
$(document).ready(function(){
	$("#dialog").dialog({
		bgiframe: true,
		autoOpen: false,
		height: 500,
		modal: true,
		width: 500,
		buttons: {
				'Gravar': function() {
					$.ajax({
			        	type: 'POST',
			            url: './admin/exec-usuarios.php',
			            data: $('#formulario').serialize(),
			            success: function(txt){
			       			alert('Registro ' + txt + ' gravado!');
			       			$('#list-usuarios tbody').prepend(txt); 
			       			$('#formulario').each(function(){
			       		        this.reset();
			       			}),
			       			$('#dialog').dialog('close');
			            },
			            error: function(txt){
			        		alert('Ocorreu um erro.');
			            }
			        });
			        return false;		
				},
				'Cancelar': function() {
					$('#formulario').each(function(){
	       		        this.reset();
	       			}),
					$(this).dialog('close');
				}
		}
	});

	$('#novo').click(function() {
		$('#dialog').dialog('open');
	});

	$('.edita').click(function() {
		alert(this.id);
	});
	
	$(".formlet").addClass("ui-widget ui-widget-content ui-helper-clearfix ui-corner-all")
	.find(".formlet-header")
		.addClass("ui-widget-header ui-corner-all")
		.end()
	.find(".formlet-content");	
});
</script>
<h2>Administração &raquo; Usuários</h2>
<div id='dialog' title='Adicionar novo Usuário'>
<form action="exec-usuarios.php" id="formulario">
	<label for="txt_nome_completo">Nome Completo:</label><br />
	<input type="text" name="txt_nome_completo" id="txt_nome_completo" size="50" class="text ui-widget-content ui-corner-all" value="<?php if(isset($nome_completo))echo $nome_completo ?>" /><br />
	<label for="txt_username">Usuário de acesso:</label><br />
	<input type="text" name="txt_username" id="txt_username" size="15" class="text ui-widget-content ui-corner-all" value="<?php if(isset($username))echo $username ?>" /><br />
	<label for="cbo_area">Área</label><br />
	<select id="cbo_area" name="cbo_area" class="select ui-widget-content ui-corner-all">
		<option value="0">Selecione uma opção</option>
		<?php echo mostra_areas(1,0); ?>
	</select><br />
	<label for="cbo_perfil">Perfil</label><br />
	<select id="cbo_perfil" name="cbo_perfil" class="select ui-widget-content ui-corner-all">
		<option value="0">Selecione uma opção</option>
		<?php echo preencheCombo('public.perfis'); ?>
	</select><br />
	<label for="cbo_filial">Filial</label><br />
	<select id="cbo_filial" name="cbo_filial" class="select ui-widget-content ui-corner-all">
		<option value="0">Selecione uma opção</option>
		<?php echo preencheCombo('public.filiais'); ?>
	</select><br />
	<label for="txt_telefone">Telefone:</label><br />
	<input type="text" name="txt_telefone" id="txt_telefone" size="4" class="text ui-widget-content ui-corner-all" /><br />
	<label for="chk_sistemas">Sistemas:</label><br />
	<?php 
	$conexao->Executar("SELECT * FROM sistemas ORDER BY id");
   	if($conexao->ContarLinhas() > 0){
           while($line = $conexao->MostrarResultados()){
				echo "<input type='checkbox' name='chk_sistemas[]' class='input ui-widget-content ui-corner-all' value='$line[0]' />$line[1]";
			}
       }
	?>
	<br />
	<label for="txt_data_nascimento">Data de Nascimento:</label><br />
	<input type="text" name="txt_data_nascimento" id="txt_data_nascimento" size="15" class="text ui-widget-content ui-corner-all campo_data" /><br />
	<label for="txt_data_admissao">Data de Admissão:</label><br />
	<input type="text" name="txt_data_admissao" id="txt_data_admissao" size="15" class="text ui-widget-content ui-corner-all campo_data" /><br />
	<label for="txt_email">Email:</label><br />
	<input type="text" name="txt_email" id="txt_email" size="50" class="text ui-widget-content ui-corner-all" /><br />
	<label for="cbo_gestor">Gestor</label><br />
	<select id="cbo_gestor" name="cbo_gestor" class="select ui-widget-content ui-corner-all">
		<option></option>
		<?php 
		$conexao->Executar("SELECT id, nome_completo FROM usuarios WHERE cargo = 1 ORDER BY id");
    	if($conexao->ContarLinhas() > 0){
            while($line = $conexao->MostrarResultados()){
					echo "<option value='$line[0]'>$line[1]</option>";
				}
        }
		?>
	</select><br />
	<label for='txt_observacoes'>Observações:</label><br />
	<textarea rows='15' cols='70' id='txt_observacoes' name='txt_observacoes' title='Observações.' class='textarea ui-widget-content ui-corner-all' ></textarea><br />	
</form>
</div>
<div id="lista" class="ui-widget">
<?php controles(false,1,false,1,1,1) ?> 
<table class="ui-widget ui-widget-content" id="list-usuarios">
	<thead>
		<tr class="ui-widget-header ">
			<th>Ações</th>
			<th>ID</th>
			<th>Nome</th>
			<th>Área</th>
			<th>Perfil</th>
		</tr>
	</thead>
	<tbody>
<?php
$sql = "SELECT usuarios.id, usuarios.nome_completo, areas.descricao AS area, perfis.descricao as perfil "; 
$sql .= "FROM usuarios ";
$sql .= "INNER JOIN areas ON areas.id = usuarios.area ";
$sql .= "INNER JOIN perfis ON perfis.id = usuarios.perfil";
$conexao->Executar($sql);
   if($conexao->ContarLinhas() > 0){
   	while($line = $conexao->MostrarResultados()){
       	echo "<tr>
       	<td><img src='$imagens/delete.png' alt='Deletar' id='$line[0]' title='Deletar o usuário $line[1]' /></td>
		<td>$line[0]</td>
		<td><a href='?aplicativo=admin&amp;subaplicativo=usuario-form&amp;acao=editar&amp;id=$line[0]' title='Editar entrada'>$line[1]</a></td>
		<td>$line[2]</td>
		<td>$line[3]</td>
		</tr>
		";
	}
}
$conexao->Liberar();        
?>
</tbody>
</table>
</div>
</form>
<br />
